package com.future.controller;

import com.future.domain.Comment;
import com.future.domain.DTO.CommentDTO;
import com.future.domain.Result;
import com.future.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@Api(tags = "评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    @ApiOperation("添加评论")
    public Result addComment(@RequestBody CommentDTO dto) {
        return commentService.addComment(dto);
    }

    @ApiOperation("获取目标类型的顶级评论")
    @GetMapping("/topLevel")
    public Result getTopLevelComments(@RequestParam Long targetId,
                                      @RequestParam Integer targetType,
                                      @RequestParam(defaultValue = "1") int pageNum,
                                      @RequestParam(defaultValue = "10") int pageSize){
        return commentService.getTopLevelComments(targetId,targetType,pageNum,pageSize);
    }

//    @GetMapping("/list")
//    @ApiOperation("获取文章评论树（全部评论）")
//    public Result getCommentsByArticle(
//            @RequestParam Long articleId,
//            @RequestParam(defaultValue = "1") int pageNum,
//            @RequestParam(defaultValue = "10") int pageSize
//    ) {
//        return commentService.getCommentsByArticle(articleId, pageNum, pageSize);
//    }

    @GetMapping("/listByTarget")
    @ApiOperation("获取目标评论树（支持文章、视频等多种类型）")
    public Result getCommentsByTarget(
            @RequestParam Long targetId,
            @RequestParam Integer targetType,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize
    ) {
        return commentService.getCommentsByTarget(targetId, targetType, pageNum, pageSize);
    }

    @GetMapping("/children")
    @ApiOperation("获取父评论的子评论")
    public Result getChildComments(
            @RequestParam Long targetType,
            @RequestParam Long parentId,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize
    ) {
        return commentService.getChildComments(parentId, pageNum, pageSize,targetType);
    }

    @DeleteMapping("/{commentId}")
    @ApiOperation("删除评论及其子评论")
    public Result deleteComment(@PathVariable Long commentId) {
        return commentService.deleteComment(commentId);
    }



}